package com.zzyl.config;

import cn.hutool.core.convert.Convert;
import com.zzyl.intercept.JwtTokenInterceptor;
import com.zzyl.intercept.MobileInterceptor;
import com.zzyl.properties.SecurityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * WebMvc高级配置类
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private MobileInterceptor mobileInterceptor;
    @Autowired
    private JwtTokenInterceptor jwtTokenInterceptor;
    @Autowired
    private SecurityProperties securityProperties;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //小程序的拦截器
        registry.addInterceptor(mobileInterceptor)
                .excludePathPatterns("/customer/user/login")
                .addPathPatterns("/customer/**");

        //管理端的拦截器
        List<String> ignoreUrl = securityProperties.getIgnoreUrl();
        registry.addInterceptor(jwtTokenInterceptor)
                .excludePathPatterns(Convert.toStrArray(ignoreUrl))
                .addPathPatterns("/**");
    }
}